<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= request.getParameter("id") != null ? "编辑学生 - 学生信息管理系统" : "添加学生 - 学生信息管理系统" %></title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="container">
            <a href="index.jsp" class="navbar-brand">学生信息管理系统</a>
            <ul class="navbar-menu">
                <li><a href="index.jsp">首页</a></li>
                <li><a href="student-management.jsp">学生管理</a></li>
                <li><a href="class-management.jsp">班级管理</a></li>
                <li><a href="score-management.jsp">成绩管理</a></li>
                <li><a href="#" onclick="alert('退出登录'); return false;">退出登录</a></li>
            </ul>
        </div>
    </nav>
    
    <div class="container">
        <h1><%= request.getParameter("id") != null ? "编辑学生信息" : "添加学生信息" %></h1>
        
        <!-- 显示消息提示 -->
        <% if (request.getAttribute("message") != null) { %>
            <div class="message success">
                <%= request.getAttribute("message") %>
            </div>
        <% } %>
        
        <% if (request.getAttribute("error") != null) { %>
            <div class="message error">
                <%= request.getAttribute("error") %>
            </div>
        <% } %>
        
        <div class="form-container" style="max-width: 700px;">
            <div class="error-container" style="display: none;"></div>
            
            <form id="studentForm" action="student" method="post" data-validate>
                <!-- 隐藏字段，用于区分添加和编辑操作 -->
                <input type="hidden" name="action" value="<%= request.getParameter("id") != null ? "update" : "insert" %>">
                <% if (request.getParameter("id") != null) { %>
                    <input type="hidden" name="studentId" value="<%= request.getParameter("id") %>">
                <% } %>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="studentId">学号</label>
                        <input type="text" id="studentId" name="studentId" <%= request.getParameter("id") != null ? "readonly" : "required" %> 
                               value="<%= request.getParameter("id") != null ? request.getParameter("id") : "" %>" 
                               placeholder="请输入学号">
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="fullName">姓名 <span style="color: red;">*</span></label>
                        <input type="text" id="fullName" name="fullName" required placeholder="请输入姓名">
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="gender">性别 <span style="color: red;">*</span></label>
                        <select id="gender" name="gender" required>
                            <option value="">请选择性别</option>
                            <option value="male">男</option>
                            <option value="female">女</option>
                        </select>
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="age">年龄 <span style="color: red;">*</span></label>
                        <input type="number" id="age" name="age" min="14" max="30" required placeholder="请输入年龄">
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="grade">年级 <span style="color: red;">*</span></label>
                        <select id="grade" name="grade" required>
                            <option value="">请选择年级</option>
                            <option value="2020">2020级</option>
                            <option value="2021">2021级</option>
                            <option value="2022">2022级</option>
                            <option value="2023">2023级</option>
                        </select>
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="major">专业 <span style="color: red;">*</span></label>
                        <select id="major" name="major" required>
                            <option value="">请选择专业</option>
                            <option value="computer">计算机科学与技术</option>
                            <option value="software">软件工程</option>
                            <option value="network">网络工程</option>
                            <option value="ai">人工智能</option>
                        </select>
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="className">班级 <span style="color: red;">*</span></label>
                        <select id="className" name="className" required>
                            <option value="">请选择班级</option>
                            <option value="1">1班</option>
                            <option value="2">2班</option>
                            <option value="3">3班</option>
                            <option value="4">4班</option>
                        </select>
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="birthDate">出生日期 <span style="color: red;">*</span></label>
                        <input type="date" id="birthDate" name="birthDate" required>
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="phone">联系电话 <span style="color: red;">*</span></label>
                        <input type="tel" id="phone" name="phone" required placeholder="请输入联系电话">
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="email">电子邮箱</label>
                        <input type="email" id="email" name="email" placeholder="请输入电子邮箱">
                    </div>
                </div>
                
                <div class="form-group">
                    <label for="address">家庭住址</label>
                    <textarea id="address" name="address" rows="3" placeholder="请输入家庭住址"></textarea>
                </div>
                
                <div class="form-group">
                    <label for="remark">备注</label>
                    <textarea id="remark" name="remark" rows="2" placeholder="请输入备注信息"></textarea>
                </div>
                
                <div class="form-group" style="margin-top: 30px;">
                    <button type="submit" class="btn btn-primary" style="margin-right: 10px;">保存</button>
                    <a href="student-management.jsp" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </div>
    </div>
    
    <script src="js/script.js"></script>

</body>
</html>